<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="inc/header"></head>

<body th:with="menu='content'" >
<nav th:replace="inc/nav"></nav>

<div class="container-fluid">
  <div class="row">
    <div th:replace="inc/sidebar"></div>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
      <h1 class="page-header">
        信息发布
      <div class="pull-right">
        <a href="./addPage" class="btn btn-primary btn-sm">新增</a>
      </div>
      </h1>
      <table class="table table-striped">
        <thead>
        <tr>
          <th>一级分类</th>
          <th>二级分类</th>
          <th>标题</th>
          <th>标题缩写</th>
          <th>创建时间</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="item : ${contents.content}">
          <td th:text="${item.type.subType == 'lawType'? '法律法规' : '信息发布'}"></td>
          <td th:text="${item.type.name}"></td>
          <td th:text="${item.title}"></td>
          <td th:text="${item.miniTitle}"></td>
          <td th:text="${item.createTime}"></td>
          <td>
            <a th:href="${#httpServletRequest.getContextPath()} + '/content/admin/editPage?id=' + ${item.id}" class="btn btn-primary btn-xs">修改</a>
            <button class="btn btn-danger btn-xs btnDelete" th:attr="data-id=${item.id}">删除</button>
          </td>
        </tr>
        </tbody>
      </table>
      <nav th:if="${contents.content.size()} > 0">
        <ul class="pagination">
          <li th:each="i : ${#numbers.sequence(1, contents.getTotalPages())}">
            <a th:href="${#httpServletRequest.getContextPath()} + '/content/admin/main?jsbh=' + ${jsbh} + '&page=' + ${i - 1}" th:text="${i}"></a>
          </li>
        </ul>
      </nav>
    </div>
  </div>
</div>

<div th:replace="inc/footer"></div>
<script  th:inline="javascript">
  $(function () {
    // 删除按钮
    $('.btnDelete').on('click', function () {
      var id = $(this).attr('data-id');
      $.ajax({
        url: [[${#httpServletRequest.getContextPath()} + '/content/delete']],
        method: 'post',
        dataType:"text",
        data: {
          id: id
        },
        success: function () {
          location.href = [[${#httpServletRequest.getContextPath()} + '/content/admin/main?jsbh=' + ${jsbh}]]
        },
        error: function () {
          alert('删除失败');
        }
      })
    })
  });
</script>
</body>
</html>
